#include "stdafx.h"
#include "State.h"

State::State() {
	m_currentModel = NULL;
	initializeControllers();

}

State::~State() {
	delete m_controllers;
	m_controllers = NULL;
}

void State::initializeControllers() {
	m_controllers = new std::list<Controller*>();

}

void State::addController(Controller *controller) {
	m_controllers->push_back(controller);
}

void State::removeController(Controller *controller) {
	m_controllers->remove(controller);
}

bool State::update(float deltaTime) {
	std::list<Controller*>::iterator i;
	for(i=m_controllers->begin(); i != m_controllers->end(); ++i) {
		if ((*i)->isActive()) {
			bool result = (*i)->update(deltaTime);
			if(!result) {
				return false;
			}
		}
	}
	if(m_currentModel) {
		m_currentModel->update(deltaTime);
	}
	return true;
}


void State::setModel(Model* model) {
	m_currentModel = model;

}
Model* State::getModel() {
	return m_currentModel;
		
}